<template>
  <div>
    <el-page-header @back="goBack">
</el-page-header>
<div style="height: 60px;"></div>
<el-form ref="form" :model="data" label-width="90px">
  <el-form-item label="供应商名称" >
    <el-input v-model="data.name" placeholder="请输入供应商名称"></el-input>
  </el-form-item>
  <el-upload
    class="avatar-uploader"
    action="http://localhost:8080/api/file/upload/"
    :show-file-list="false"
    :on-success="handleAvatarSuccess"
    :before-upload="beforeAvatarUpload">
    <img v-if="imageUrl" :src="imageUrl" class="avatar">
    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  </el-upload>
  <el-form-item label="供应商简称">
    <el-input v-model="data.abbreviation" placeholder="请输入供应商简称"></el-input>
  </el-form-item>
  <el-form-item label="供应商代号" >
    <el-input v-model="data.mark" placeholder="请输入供应商代号"></el-input>
  </el-form-item>
  <el-form-item label="供应商编码" >
    <el-input v-model="data.encoding" placeholder="请输入供应商编码"></el-input>
  </el-form-item>
  <el-form-item label="供应商区域" >
    <el-input v-model="data.area" placeholder="请输入供应商区域"></el-input>
  </el-form-item>
  <el-form-item label="供应商邮箱" >
    <el-input v-model="data.email" placeholder="请输入供应商邮箱"></el-input>
  </el-form-item>
  <el-form-item  >
    <el-button type="primary" @click="commit()">提交</el-button>
  </el-form-item>
</el-form>
  </div>
</template>
<script>
export default{
  data(){
    return {
      imageUrl:'',
      data:{
        name:'',
        type:1,
        image:'',
        abbreviation:'',
        mark:'',
        encoding:'',
        area:'',
        email:''
      }
      
    }
  },
  methods: {

    handleAvatarSuccess(res, file) {
      console.log(res);
        this.imageUrl = URL.createObjectURL(file.raw);
        this.data.image = res.data
        console.log(this.data.image);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt3M = file.size / 1024 / 1024 /1024 < 3;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt3M) {
          this.$message.error('上传头像图片大小不能超过 3MB!');
        }
        return isJPG && isLt3M;
      },
      goBack(){
        this.$router.push("/vendor")
      },
      commit(){
        console.log(this.data);
        this.$axios.post("businessCompetitor/addClient",this.data).then(res => {
          if(res.data.code == 200){
            this.$message.success("添加成功")
            this.$router.push("/vendor")
          }else{
            this.message.error("添加失败");
          }
        })
      }
    },
}
</script>
<style scoped>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }</style>